package sysu.el.audit;

import java.util.ArrayList;

import sysu.el.array.ints.functors.Fun1;
import sysu.el.array.ints.functors.Fun1.Int;

/*
 * Easy to use.
 */
public class AuditInt {
	public int min, max;
	public int num;
	public long sum;
	public AuditInt(){
		min = Integer.MAX_VALUE;
		max = Integer.MIN_VALUE;
	}
	
	//-EL-TODO: Typical Command Line Pattern
	public ArrayList<Int> funs = new ArrayList<Fun1.Int>(3);
	public void addFunctor(Fun1.Int f){
		funs.add(f);
	}
	
	public void sample(int value){
		min = Math.min(value, min);
		max = Math.max(value, max);
		sum += value;
		num ++;
		for (Fun1.Int f : funs) f.apply(value);
	}
	
	public void sample(int[] values){
		for (int e:values) sample(e);
	}
	
	public void sample(Integer[] values){
		for (Integer e:values) sample(e);
	}
	
	public double getAvg(){
		return (sum / (double)num);
	}
	public long getSum(){
		return sum;
	}
	public int getMin(){
		return min;
	}
	public int getMax(){
		return max;
	}
	
}
